(ns blade-art-online.core
  (:use ring.util.response
        ring.adapter.jetty
        ring.middleware.resource)
  (:require 
            [clojure.string :as str]
            [ring.util.request :refer [body-string]]
            ;[middleware.body-parser :refer [body-parser]]
            [simple-body-parser.wrapper :refer [wrap-bodys]]
            [blade-art-online.user :as user]
            [blade-art-online.player :as player]
            [ring.middleware.json :refer [wrap-json-response]]
            [ring.middleware.session :refer [wrap-session]]
            [ring.middleware.cookies :refer [wrap-cookies]]))




(defn route 
  "My simple router implement"
  [{uri :uri :as request}]
  (cond
    (user/uri-match? uri) (user/handle request)
    
    :else (response "Page not found!") ))

(defn show-uri
  [handler]
  (fn [request]
    (prn request)
    (-> request
        handler)))
  

(def app
  (-> route
      (wrap-json-response)
      (show-uri)
      (wrap-session)
      ; (wrap-cookies)
      (wrap-bodys)
      (wrap-resource "fuck")))

; (run-jetty app {:port 8080})